@ECHO OFF

REM 应用程序路径

REM 设置字符编码
chcp 65001 > nul

setlocal

set appPath=%~1
set act=%~2
set type=%~3

if "%type%"=="" (
    set type=script
)

REM 检查传入文件路径是否正确

if "%appPath%"=="" ( 
    echo 应用程序路径未设置
    exit /b 1
)

if not exist "%appPath%" (
	echo %appPath% 不存在，请输入正确路径
	exit /b 2
)


SET appName=%~nx1

set regAppPath=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\%appName%
reg query "%regAppPath%" 1>nul 2>nul
rem 这里没有时会报错，并输出错误信息，不用管，逻辑正常处理了
if %errorlevel%==0 (
    rem echo delete "%regAppPath%"
    reg delete "%regAppPath%" /f 1>nul 2>nul
)
if "%act%"=="install" (
    REG ADD "%regAppPath%" /ve /t REG_SZ /d "%appPath%" 1>nul 2>nul
    if "%type%"=="script" (
        echo -----------    添加应用程序索引完成    ------------------------------------------------------
        pause
    )
    exit /b %errorlevel%
)

if "%act%"=="uninstall" (
    REM reg delete "%regAppPath%" /f 1>nul 2>nul
    if "%type%"=="script" (
        echo -----------    移除应用程序索引完成    ------------------------------------------------------
        pause
    )
    exit /b %errorlevel%
)

exit /b 99